package sort;

/**
 * 简单选择排序
 *
 * @param <T>
 * @author zj
 */
@SuppressWarnings("unchecked")
public class SelectSort<T extends Comparable<T>> implements Sort<T> {
    @Override
    public void sort(T[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            T min = arr[i];
            int k = i;
            for (int j = i; j < arr.length; j++) {
                if (arr[j].compareTo(min) < 0) {
                    min = arr[j];
                    k = j;
                }
            }
            arr[k] = arr[i];
            arr[i] = min;
        }
    }
}
